#ifndef QSERVERMANAGER_H
#define QSERVERMANAGER_H

#include "devicelibglobal.h"

#include <QObject>
#include <QMap>
#include <QTimer>
#include <QDateTime>
#include <QStringList>

struct tagDeviceInfo;
struct tagServerInfo;
class QDeviceClient;
class QClientUpdate;
class QSendFile;

class DEVICELIB_EXPORT QServerManager : public QObject
{
    Q_OBJECT
public:
    explicit QServerManager(tagDeviceInfo *info,QObject *parent = 0);
    ~QServerManager();
protected:
    void    recv_update(const QByteArray& data);
    void    recv_data_sync(const QByteArray& data);
    void    clear_locked();

    void    driver_listern(const QByteArray& data);

    void    database_update(const QByteArray& data);
signals:
    void    server_offline(const QString &uuid);
    void    update_success();
protected slots:
    void    new_server(tagServerInfo* device);
    void    delete_server(const QString &uuid);

    void    recv_data(const QByteArray& data);
    void    data_changed(const QString &data_uuid);
    void    timer();

    void    report_driver_message(const QString &msg);
protected:
    tagDeviceInfo                       *m_device_info;
    QList<tagServerInfo*>               m_servers;
    QMap<QString,tagServerInfo*>        m_uuid_to_server;
    QDeviceClient                       *m_device_client;
    QClientUpdate                       *m_client_update;
    QDateTime                           m_last_update_time;
    QDateTime                           m_last_data_sync_time;
    QTimer                              *m_timer;
    QList<QString>                      m_data_changed_list;
    QStringList                         m_sync_servers;
    QMap<QString,QSendFile*>            m_uuid_to_sendfile;
};

#endif // QSERVERMANAGER_H
